<?php

namespace haibao\ad\data;

class Banner extends \haibao\ad\data\BaseMysql {
	public function __construct() {
		parent::__construct ( '\haibao\ad\model\data\AdSummary' );
	}
	
	public function getTodayAdInfo($date){
		$adArr = array();
		$sql = 'SELECT b.*,z.interface_zone_id,o.weight as order_weight from banners as b LEFT JOIN banner_acls as ac ON b.bannerid = ac.bannerid LEFT JOIN zones as z ON b.zone_id = z.zoneid LEFT JOIN orders as o ON b.order_id = o.id WHERE b.weight=%s AND (ac.`data`=%s or (b.yizhi=%s AND z.affiliateid > %s))';
		$result = $this->query($sql,array(\haibao\ad\model\data\Banner::WEIGHT_HIGH,$date,\haibao\ad\model\data\Banner::YIZHI_YES,1));
		while ($row = $result->fetch_assoc()){
			$model = new \haibao\ad\model\data\Banner();
			$model->loadArray($row);
			if(!isset($adArr[$model->interface_zone_id])){
				$adArr[$model->interface_zone_id] = array();
			}
			$adArr[$model->interface_zone_id][$model->bannerid] = $model;
		}
		return $adArr;
	}
	
	public function getTodayTestAdInfo($date){
		$adArr = array();
		$sql = 'SELECT b.*,z.interface_zone_id FROM banners as b LEFT JOIN zones as z ON b.zone_id = z.zoneid WHERE b.datastr LIKE "'.$date.'" ORDER BY b.bannerid DESC LIMIT 20';
		$result = $this->query($sql);
		while ($row = $result->fetch_assoc()){
			$model = new \haibao\ad\model\data\Banner();
			$model->loadArray($row);
			if(!isset($adArr[$model->interface_zone_id])){
				$adArr[$model->interface_zone_id] = array();
			}
			$adArr[$model->interface_zone_id][$model->bannerid] = $model;
		}
		return $adArr;
	}
}
